package com.naodong.shenluntiku.mvp.view.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;

import com.naodong.shenluntiku.R;

/**
 * Created by hujie on 17/6/8.
 */

public class HighLight extends View {

    Paint hightLightPaint;
    int[] hightLightPosition;
    int radius = 100;

    public HighLight(Context context) {
        super(context);
        init();
    }

    public HighLight(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public HighLight(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        setBackgroundColor(ContextCompat.getColor(getContext(), R.color.black));
        setAlpha(0.5f);
        hightLightPaint = new Paint();
        hightLightPaint.setColor(ContextCompat.getColor(getContext(), R.color.black));
        hightLightPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.XOR));
        radius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, getResources().getDisplayMetrics());
    }

    public void setHightLightPosition(int[] hightLightPosition) {
        this.hightLightPosition = hightLightPosition;
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (hightLightPosition != null) {
            canvas.drawCircle(hightLightPosition[0], hightLightPosition[1], radius, hightLightPaint);
        }
    }
}
